from flask import Flask

from com.linkstec.controller.route_test_controller import RouteTestController
from com.linkstec.controller.company_info_controller import CompanyInfoController
from com.linkstec.controller.user_controller import UserController
from com.linkstec.utils.db_utils import DatabasePool

app = Flask(__name__)

user_controller = UserController()
company_info_controller = CompanyInfoController()

# 初始化数据库连接池
DatabasePool.get_instance()

# 注册路由: 方式1
user_controller = UserController()
app.add_url_rule('/users/add', 'create_user', user_controller.create_user, methods=['POST'])
app.add_url_rule('/users/update/<int:user_id>', 'update_user', user_controller.update_user, methods=['POST'])
app.add_url_rule('/users/delete/<int:user_id>', 'delete_user', user_controller.delete_user, methods=['GET'])
app.add_url_rule('/users/<int:user_id>', 'get_user', user_controller.get_user, methods=['GET'])
app.add_url_rule('/users', 'list_users', user_controller.list_users, methods=['GET'])

app.add_url_rule('/company', 'list_company_info', company_info_controller.list_company_info, methods=['GET'])
app.add_url_rule('/company/getName', 'get_company_info', company_info_controller.get_company_info, methods=['POST'])

# 注册路由: 方式2,app传入到controller中使用
test_controller = RouteTestController(app)



if __name__ == '__main__':
    app.run(host='0.0.0.0', port=9200, debug=True)